package com.canbot.u05.activity.shoppingGuide.merchandiseShoppingGuide;

import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import com.canbot.u05.R;
import com.canbot.u05.activity.BaseActivityNoTitle;
import com.canbot.u05.utils.Logger;

/**
 * 欢迎语音设置界面
 */
public class WelcomActivity extends BaseActivityNoTitle implements View.OnClickListener {

        private final static String TAG = "WelcomActivity";

        private Button btnBack, btnSure;

        private EditText editText;

        private String question;

        @Override
        protected void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.activity_welcom);

                question = getIntent().getStringExtra("text");
                setViews();
        }

        private void setViews() {

                btnBack = (Button) findViewById(R.id.shopping_guide_btn_delete);
                btnSure = (Button) findViewById(R.id.btn_sure);
                btnBack.setOnClickListener(this);
                btnSure.setOnClickListener(this);
                editText = (EditText) findViewById(R.id.et_welcom);
                if (!TextUtils.isEmpty(question)) {
                        editText.setText(question);
                }
                editText.addTextChangedListener(new TextWatcher() {
                        @Override
                        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

                        }

                        @Override
                        public void onTextChanged(CharSequence s, int start, int before, int count) {
                        }

                        @Override
                        public void afterTextChanged(Editable s) {
                                Logger.e(TAG, "改变的问题=" + s.toString());
                        }
                });

                editText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
                        @Override
                        public void onFocusChange(View v, boolean hasFocus) {
                                if (hasFocus) {
                                        editText.setSelection(editText.length());
                                }
                        }
                });
        }

        @Override
        public void onClick(View view) {
                switch (view.getId()) {
                        case R.id.shopping_guide_btn_delete:
                                setResult(RESULT_CANCELED);
                                //返回
                                finish();
                                overridePendingTransition(R.anim.face_zoom_enter,
                                        R.anim.face_zoom_exit);
                                break;
                        case R.id.btn_sure:
                                //确定
                                String welcomText = editText.getText().toString();
                                Logger.e(TAG, "欢迎语音==" + welcomText);
                                Intent intent = new Intent();
                                intent.putExtra("isChecked", true);
                                intent.putExtra("text", welcomText);
                                setResult(RESULT_OK, intent);
                                finish();
                                overridePendingTransition(R.anim.face_zoom_enter,
                                        R.anim.face_zoom_exit);
                                break;

                }
        }
}
